
<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-position="labelPosition" class="demo-ruleForm" label-width="160px">
			<el-row :gutter="16">
                    <el-col :span="12">
						<div  class="container">
							<el-form-item label="选择模板：" prop="clientName">
								<el-select v-model="mubans" filterable @change="getmuban" value-key="id" placeholder="请选择" style="width:300px">
									<el-option
									v-for="(item,index) in muban"
									:key="index"
									:label="item.name"
									:value="item.name">
									</el-option>
								</el-select>
							</el-form-item>
							<!-- <el-form-item label="产品大类：" prop="clientName" v-if="mubans != '打印模板（省标）'">
								<el-select v-model="fenlei" filterable @change="getfenlei" value-key="id" placeholder="请选择" style="width:300px">
									<el-option
									v-for="(item,index) in fenleis"
									:key="index"
									:label="item.templateName"
									:value="item">
									</el-option>
								</el-select>
							</el-form-item> -->
						</div>
                    </el-col>

                </el-row>
				<div v-if="mubans != '打印模板（省标）'">
					<el-row :gutter="16">
						<el-col :span="12">
							<div class="container">
								<h3 style="margin-bottom: 20px">打印预览({{printname}})</h3>
								<div class="codeView" style="min-height: 200px">
                  <div v-if="ruleForm.inventoryType == 'C70中药配方颗粒' || ruleForm.inventoryType == 'C90中药配方颗粒'" class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
                  <div v-if="ruleForm.inventoryType == 'C70中药配方颗粒' || ruleForm.inventoryType == 'C90中药配方颗粒'" style="padding-left:20px;">{{barCode}}</div>
									<h5>{{ruleForm.breedName}}</h5>

									<el-form-item v-for="(item,index) in arrcontent" :key="index" :label="item.name + ''" >
										&nbsp;&nbsp;
										<span >{{item.details}}</span>

									</el-form-item>
									<div class="img"><img :src=" imgs " /></div>
								</div>
							</div>
						</el-col>
					</el-row>
				</div>

				<div v-if="mubans == '打印模板（省标）'">
					<el-row :gutter="16" v-if="type == 'C20连袋中药配方颗粒'">
						<el-col :span="12">
							<div class="container">
								<h3 style="margin-bottom: 20px">打印预览(C20连袋中药配方颗粒)</h3>
								<div class="codeView" style="min-height: 200px">

									<h5>{{ruleForm.breedName}}</h5>

									<el-form-item v-for="(item,index) in content3" :key="index" :label="item.name + ''" >
										&nbsp;&nbsp;
										<span >{{item.details}}</span>

									</el-form-item>
									<div class="img"><img :src=" imgs " /></div>
								</div>
							</div>
						</el-col>
					</el-row>
				<el-row :gutter="16" v-if="type == 'C20中药配方颗粒'">
					<el-col :span="12">
						<div class="container">
							<h3 style="margin-bottom: 20px">打印预览(C20中药配方颗粒)</h3>
							<div class="codeView" style="min-height: 200px">
								<h5>{{ruleForm.breedName}}</h5>
								<el-form-item v-for="(item,index) in content" :key="index" :label="item.name + ''" >
									&nbsp;&nbsp;
									<span >{{item.details}}</span>
								</el-form-item>
								<div class="img"><img :src=" imgs " /></div>
							</div>
						</div>
					</el-col>
				</el-row>
				<el-row>
					<el-col v-if="type == 'C50中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C50中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
										<p style="padding-left:20px;">{{barCode}}</p>
										<h5>{{ruleForm.breedName}}</h5>


										<el-form-item v-for="(item,index) in content1" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>
										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C51中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C51中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
										<p style="padding-left:20px;">{{barCode}}</p>
										<h5>{{ruleForm.breedName}}</h5>


										<el-form-item v-for="(item,index) in content4" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>
										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C50天津中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C50天津中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
										<div style="padding-left:20px;">{{barCode}}</div>
										<h5>{{ruleForm.breedName}}</h5>
										<el-form-item v-for="(item,index) in content2" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>

										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C60中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C60中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<!-- <div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div> -->
										<!-- <div style="padding-left:20px;">{{barCode}}</div> -->
										<h5>{{ruleForm.breedName}}</h5>
										<el-form-item v-for="(item,index) in content6" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>

										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C70中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C70中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
										<div style="padding-left:20px;">{{barCode}}</div>
										<h5>{{ruleForm.breedName}}</h5>
										<el-form-item v-for="(item,index) in content7" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>

										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C80中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C80中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<!-- <div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div> -->
										<!-- <div style="padding-left:20px;">{{barCode}}</div> -->
										<h5>{{ruleForm.breedName}}</h5>
										<el-form-item v-for="(item,index) in content8" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>

										<div class="img"><img :src=" imgs " /></div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
					<el-col v-if="type == 'C90中药配方颗粒'">
						<el-row :gutter="16">
							<el-col :span="12">
								<div class="container">
									<h3 style="margin-bottom: 20px">打印预览(C90中药配方颗粒)</h3>
									<el-row class="container codeView codeViewC50">

										<div class="codeimg"><img src="../../../../assets/img/codeImg1.png" width="50%" /></div>
										<div style="padding-left:20px;">{{barCode}}</div>
										<h5>{{ruleForm.breedName}}</h5>
										<el-form-item v-for="(item,index) in content9" :key="index" :label="item.name + ''" >
											&nbsp;&nbsp;
											<span>{{item.details}}</span>

										</el-form-item>

										<div class="img">
											<img :src=" imgs " width="50%" alt=""/>
										
										</div>
									</el-row>
								</div>
							</el-col>
						</el-row>
					</el-col>
				</el-row>
				</div>

        <div class="container" style="margin-top: 20px">
            <h3 style="margin-bottom: 20px">打印发送</h3>
            <el-row>
                <el-col>
                    <el-form-item label="申请码数：" prop="printNum">
                        <el-input v-model.number="ruleForm.printNum" type="number" @change="changeNum" style="width:300px"></el-input>
                        &nbsp;&nbsp;
                        未打印： {{most}}
                        &nbsp;&nbsp;
                        已打印： {{lastPrintNum}}


                    </el-form-item>
                </el-col>
            </el-row>
        </div>
        <el-form-item class="footerFixed">
            <el-button type="primary" @click="submitRules('ruleForm')" :disabled="disabled">提交</el-button>
            <el-button @click="backPage">返回</el-button>
        </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {print_findMsg,print_detail,print_send,template_get} from "@/request/api";
import {template_findByCompanyId} from "@/request/manageapi"
    export default {
        components: {

        },
        data() {
            return {
				code1:'',
				disabled:false,
				labelPosition:"left",
                show: false,
                C50tj: false,
                name1: '产品批号',
                name2: '规格',
                name3: '相当于饮片',
                name4: '生产日期',
                name5: '有效期至',
                name1_1: '批号',
                name2_1: '临床当量',
                name2_1_1: '规格',
                name3_1: '配方颗粒相当于临床使用饮片量',
                name3_1_1: '相当于饮片',
                name4_1: '生产日期',
                name5_1: '有效期至',
                name6_1: '包装规格',
                name7_1: '每袋装',
                barCode: '',
				content2:"",
				content1:'',
				content:'',
				content3:'',
				content4:'',
                content6:'',
                content7:'',
				content8:'',
				content9:'',
				bench:"",
				imgs:"",
                ruleForm: {
                    scTime: '',
                    printNum: ''
                },
                rules: {
                    printNum: [
                        { required: true, message: '不能为空', trigger: 'blur' },
                    ],
                },
                most: '',
                lastPrintNum: '',
                endPrintNum: 0,
				muban:[
					{name:"打印模板（国标）"},
					{name:'打印模板（省标）'},
					{name:'打印模板（国标C60）-上海'},
					{name:'打印模板（国标C70）-上海'},
					{name:'打印模板（省标C80）-上海'},
					{name:'打印模板（省标C90）-上海'},
					{name:'打印模板（国标）-上海'},
					{name:'打印模板（省标）-执行标准-详见二维码'}
					],
				mubans:'打印模板（国标）',
				fenleis:[],
				fenlei:'',
				arrcontent:[],
				printname:'',
				type:''
            };
        },
        mounted(){
			// console.log(this.$route.query)
            this.id = this.$route.query.id
			this.bench = this.$route.query.bench
            this.endPrintNum = Number(this.$route.query.endNum)
            this.lastPrintNum = Number(this.$route.query.lastPrintNum)
            this.most = Math.round((this.endPrintNum)-this.lastPrintNum)
			// this.getnewprint()
            this.init();
			// this.getnewprint()
        },
		created(){
			if(process.env.NODE_ENV === 'development'){
				this.imgs = 'http://192.168.1.197:81/print/getCodeByBatch?batch='+this.$route.query.bench
			}else{
				this.imgs = "http://" + window.location.host + '/print/getCodeByBatch?batch='+this.$route.query.bench
			}
		},
        methods: {
			getmuban(e){
				if(e == "打印模板（省标）"){
					this.getoldprint()
				}else if(e == '打印模板（国标）'){
					this.getnewprint()
				}else if(e== '打印模板（国标）-上海'){
          let companyId = localStorage.getItem("companyId") +"&isNew=3"
          template_findByCompanyId(`?companyId=${companyId}`).then((res)=>{
            this.fenleis = res.data
            console.log(res)
            for(var i=0;i<this.fenleis.length;i++){
              var s = this.fenleis[i].type.substring(0,3)
              // console.log(s)
              if(this.code1 == s){
                this.getfenlei(this.fenleis[i])
              }
            }
          })
        }else if(e == '打印模板（省标）-执行标准-详见二维码'){
          let companyId = localStorage.getItem("companyId") +"&isNew=4"
          template_findByCompanyId(`?companyId=${companyId}`).then((res)=>{
            this.fenleis = res.data
            for(var i=0;i<this.fenleis.length;i++){
              var s = this.fenleis[i].type.substring(0,3)
              if(this.code1 == s){
                this.getfenlei2(this.fenleis[i])
              }
            }
          })
        }
			},
			getoldprint(){
				// console.log(this.type)
				if(this.type == 'C20中药配方颗粒'){
						let data = "?type=c20pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content = JSON.parse(res.data.content)
							for (var i = 0; i < this.content.length; i++) {
								if(this.content[i].type == "批号"){
									this.content[i].details = this.ruleForm.batch
								}
								if(this.content[i].type == "生产日期"){
									this.content[i].details = this.ruleForm.scTime
								}
								if(this.content[i].type == "有效期至"){
									this.content[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content[i].type == "规格"){
									this.content[i].details = this.content[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.content[i].details + this.ruleForm.ypQuantity+"克"
								}
								if(this.content[i].name == "贮藏"){
									this.content[i].details = this.ruleForm.storage
								}
								if(this.content[i].name == "产地"){
									this.content[i].details = this.ruleForm.address
								}
								if(this.content[i].name == "装量"){
									this.content[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}

							}
						})
					}
					if(this.type == "C50中药配方颗粒"){
						let data = "?type=c50pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content1 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content1.length; i++) {
								if(this.content1[i].type == "批号"){
									this.content1[i].details = this.ruleForm.batch
								}
								if(this.content1[i].type == "生产日期"){
									this.content1[i].details = this.ruleForm.scTime
								}
								if(this.content1[i].type == "有效期至"){
									this.content1[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content1[i].type == "规格"){
									this.content1[i].details = this.content1[i].detailone + this.ruleForm.loadingQuantity + "g" + this.content1[i].details + this.ruleForm.ypQuantity+"g"
								}
								if(this.content1[i].name == "贮藏"){
									this.content1[i].details = this.ruleForm.storage
								}
								if(this.content1[i].name == "产地"){
									this.content1[i].details = this.ruleForm.address
								}
								if(this.content1[i].name == "装量"){
									this.content1[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}
							}
						})
					}
					if(this.type == "C51中药配方颗粒"){
						let data = "?type=c51pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content4 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content4.length; i++) {
								if(this.content4[i].type == "批号"){
									this.content4[i].details = this.ruleForm.batch
								}
								if(this.content4[i].type == "生产日期"){
									this.content4[i].details = this.ruleForm.scTime
								}
								if(this.content4[i].type == "有效期至"){
									this.content4[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content4[i].type == "规格"){
									this.content4[i].details = this.content4[i].detailone + this.ruleForm.loadingQuantity + "g" + this.content4[i].details + this.ruleForm.ypQuantity+"g"
								}
								if(this.content4[i].name == "贮藏"){
									this.content4[i].details = this.ruleForm.storage
								}
								if(this.content4[i].name == "产地"){
									this.content4[i].details = this.ruleForm.address
								}
								if(this.content4[i].name == "装量"){
									this.content4[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}
							}
						})
					}
					if(this.type == "C50天津中药配方颗粒"){
						let data = "?type=c50tj&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content2 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content2.length; i++) {
								if(this.content2[i].type == "批号"){
									this.content2[i].details = this.ruleForm.batch
								}
								if(this.content2[i].type == "生产日期"){
									this.content2[i].details = this.ruleForm.scTime
								}
								if(this.content2[i].type == "有效期至"){
									this.content2[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content2[i].type == "包装规格"){
									this.content2[i].details = "每袋装" + this.ruleForm.loadingQuantity + "克"
								}
								if(this.content2[i].type == "规格"){
									this.content2[i].details = this.ruleForm.loadingQuantity + "克" + this.content2[i].details + this.ruleForm.ypQuantity+"克"
								}
								if(this.content2[i].name == "贮藏"){
									this.content2[i].details = this.ruleForm.storage
								}
								if(this.content2[i].name == "产地"){
									this.content2[i].details = this.ruleForm.address
								}
								if(this.content2[i].name == "装量"){
									this.content2[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}
							}
						})
					}
					if(this.type == "C20连袋中药配方颗粒"){
						let data = "?type=c20ld&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content3 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content3.length; i++) {
								if(this.content3[i].type == "批号"){
									this.content3[i].details = this.ruleForm.batch
								}
								if(this.content3[i].type == "生产日期"){
									this.content3[i].details = this.ruleForm.scTime
								}
								if(this.content3[i].type == "有效期至"){
									this.content3[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content3[i].type == "规格"){
									this.content3[i].details = this.content3[i].detailone + this.ruleForm.loadingQuantity + "克" + this.content3[i].details + this.ruleForm.ypQuantity + "克"
								}
								if(this.content3[i].name == "贮藏"){
									this.content3[i].details = this.ruleForm.storage
								}
								if(this.content3[i].name == "产地"){
									this.content3[i].details = this.ruleForm.address
								}
								if(this.content3[i].name == "装量"){
									this.content3[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}

							}
						})
					}
                    if(this.type == 'C60中药配方颗粒'){
						let data = "?type=c60pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content6 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content6.length; i++) {
								if(this.content6[i].type == "批号"){
									this.content6[i].details = this.ruleForm.batch
								}
								if(this.content6[i].type == "生产日期"){
									this.content6[i].details = this.ruleForm.scTime
								}
								if(this.content6[i].type == "有效期至"){
									this.content6[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content6[i].type == "规格"){
									this.content6[i].details = this.content6[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.content6[i].details + this.ruleForm.ypQuantity+"克"
								}
								if(this.content6[i].name == "贮藏"){
									this.content6[i].details = this.ruleForm.storage
								}
								if(this.content6[i].name == "产地"){
									this.content6[i].details = this.ruleForm.address
								}
								if(this.content6[i].name == "装量"){
									this.content6[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}

							}
						})
					}

                    if(this.type == 'C70中药配方颗粒'){
						let data = "?type=c70pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.fenlei = res.data
							this.content7 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content7.length; i++) {
								if(this.content7[i].type == "批号"){
									this.content7[i].details = this.ruleForm.batch
								}
								if(this.content7[i].type == "生产日期"){
									this.content7[i].details = this.ruleForm.scTime
								}
								if(this.content7[i].type == "有效期至"){
									this.content7[i].details = this.ruleForm.deadLine + "个月"
								}
								if(this.content7[i].type == "规格"){
									this.content7[i].details = this.content7[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.content7[i].details + this.ruleForm.ypQuantity+"克"
								}
								if(this.content7[i].name == "贮藏"){
									this.content7[i].details = this.ruleForm.storage
								}
								if(this.content7[i].name == "产地"){
									this.content7[i].details = this.ruleForm.address
								}
								if(this.content7[i].name == "装量"){
									this.content7[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
								}
							}
						})
					}
					if(this.type == 'C80中药配方颗粒'){
						let data = "?type=c80pt&isNew=2"
						template_get(data).then((res)=>{
							// this.id = res.data.id
							this.type1 = res.data.type
							this.fenlei = res.data
							this.content8 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content8.length; i++) {
								if(this.content8[i].type == "批号"){
									this.content8[i].details = this.ruleForm.batch
								}
								if(this.content8[i].type == "生产日期"){
									this.content8[i].details = this.ruleForm.scTime
								}
								if(this.content8[i].type == "有效期至"){
                  console.log(this.ruleForm)
									this.content8[i].details = this.ruleForm.deadLine + "个月"
								}
								// console.log(this.arrcontent[i])
								if(this.content8[i].type == "规格" && this.type1 == "c50tj"){
									this.content8[i].details =  this.ruleForm.loadingQuantity + "克"+ this.content8[i].details + this.ruleForm.ypQuantity+"克"
								}
								if(this.content8[i].name == "贮藏"){
									this.content8[i].details = this.ruleForm.storage
								}
								if(this.content8[i].name == "中药饮片执行标准"){
									this.content8[i].details = this.ruleForm.zyyp
								}
								if(this.content8[i].name == "中药配方颗粒执行标准"){
									this.content8[i].details = this.ruleForm.zypf
								}
								if(this.content8[i].name == "生产备案号"){
									this.content8[i].details = this.ruleForm.prodRecordCode
								}
								if(this.content8[i].name == "产地"){
									this.content8[i].details = this.ruleForm.address
								}
								if(this.type1 == 'c80pt'|| this.type1 == 'c90pt'){
									if(this.content8[i].name == "装量"){
										this.content8[i].details = "每袋装" + this.ruleForm.pelletWeight + 'g'
									}
									if(this.content8[i].type == "规格" && this.type != "c50tj"){
										this.content8[i].details = this.content8[i].detailone + this.ruleForm.loadingQuantity + "g"+ this.content8[i].details + this.ruleForm.ypQuantity+"g"
									}
								}else{
									if(this.content8[i].name == "装量"){
										this.content8[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
									}
									if(this.content8[i].type == "规格" && this.type1 != "c50tj"){
										this.content8[i].details = this.content8[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.content8[i].details + this.ruleForm.ypQuantity+"克"
									}
								}
							}
          console.log(this.content8)
						})
					}
					if(this.type == 'C90中药配方颗粒'){
						let data = "?type=c90pt&isNew=2"
						template_get(data).then((res)=>{
							// console.log(res)
							this.type1 = res.data.type
							// this.id = res.data.id
							this.fenlei = res.data
							this.content9 = JSON.parse(res.data.content)
							for (var i = 0; i < this.content9.length; i++) {
								if(this.content9[i].type == "批号"){
									this.content9[i].details = this.ruleForm.batch
								}
								if(this.content9[i].type == "生产日期"){
									this.content9[i].details = this.ruleForm.scTime
								}
								if(this.content9[i].type == "有效期至"){
									this.content9[i].details = this.ruleForm.deadLine + "个月"
								}
								// console.log(this.arrcontent[i])
								if(this.content9[i].type == "规格" && this.type1 == "c50tj"){
									this.content9[i].details =  this.ruleForm.loadingQuantity + "克"+ this.content9[i].details + this.ruleForm.ypQuantity+"克"
								}

								if(this.content9[i].name == "贮藏"){
									this.content9[i].details = this.ruleForm.storage
								}
								if(this.content9[i].name == "中药饮片执行标准"){
									this.content9[i].details = this.ruleForm.zyyp
								}
								if(this.content9[i].name == "中药配方颗粒执行标准"){
									this.content9[i].details = this.ruleForm.zypf
								}
								if(this.content9[i].name == "生产备案号"){
									this.content9[i].details = this.ruleForm.prodRecordCode
								}
								if(this.content9[i].name == "产地"){
									this.content9[i].details = this.ruleForm.address
								}
								if(this.type1 == 'c80pt'|| this.type1 == 'c90pt'){
									if(this.content9[i].name == "装量"){
										this.content9[i].details = "每袋装" + this.ruleForm.pelletWeight + 'g'
									}
									if(this.content9[i].type == "规格" && this.type != "c50tj"){
										this.content9[i].details = this.content9[i].detailone + this.ruleForm.loadingQuantity + "g"+ this.content9[i].details + this.ruleForm.ypQuantity+"g"
									}
								}else{
									if(this.content9[i].name == "装量"){
										this.content9[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
									}
									if(this.content9[i].type == "规格" && this.type1 != "c50tj"){
										this.content9[i].details = this.content9[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.content9[i].details + this.ruleForm.ypQuantity+"克"
									}
								}

							}
						})
					}
			},
			getnewprint(){
				let companyId = localStorage.getItem("companyId") +"&isNew=1"
				template_findByCompanyId(`?companyId=${companyId}`).then((res)=>{
					this.fenleis = res.data
					// console.log(11)
					for(var i=0;i<this.fenleis.length;i++){
						var s = this.fenleis[i].type.substring(0,3)
						// console.log(s)
						if(this.code1 == s){
							this.getfenlei(this.fenleis[i])
						}

					}
				})
			},
          getfenlei2(e){
            this.fenlei = e
            this.type1 = e.type
            this.arrcontent = e.content
            this.printname = e.templateName
            this.arrcontent = JSON.parse(this.arrcontent)
            for (var i = 0; i < this.arrcontent.length; i++) {


              if(this.arrcontent[i].type == "批号"){
                this.arrcontent[i].details = this.ruleForm.batch
              }
              if(this.arrcontent[i].type == "生产日期"){
                this.arrcontent[i].details = this.ruleForm.scTime
              }
              if(this.arrcontent[i].type == "有效期至"){
                this.arrcontent[i].details = this.ruleForm.deadLine + "个月"
              }
              // console.log(this.arrcontent[i])
              if(this.arrcontent[i].type == "规格" && this.type1 == "c50tj"){
                this.arrcontent[i].details =  this.ruleForm.loadingQuantity + "g"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"g"
              }

              if(this.arrcontent[i].name == "贮藏"){
                this.arrcontent[i].details = this.ruleForm.storage
              }
              if(this.arrcontent[i].name == "中药饮片执行标准"){
                this.arrcontent[i].details = this.ruleForm.zyyp
              }
              if(this.arrcontent[i].name == "中药配方颗粒执行标准"){
                this.arrcontent[i].details = '详见二维码'
              }
              if(this.arrcontent[i].name == "生产备案号"){
                this.arrcontent[i].details = this.ruleForm.prodRecordCode
              }
              if(this.arrcontent[i].name == "产地"){
                this.arrcontent[i].details = this.ruleForm.address
              }
              if(this.type1 == 'c60pt'|| this.type1 == 'c70pt'){
                if(this.arrcontent[i].name == "装量"){
                  this.arrcontent[i].details = "每袋装" + this.ruleForm.pelletWeight + 'g'
                }
                if(this.arrcontent[i].type == "规格" && this.type != "c50tj"){
                  this.arrcontent[i].details = this.arrcontent[i].detailone + this.ruleForm.loadingQuantity + "g"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"g"
                }
              }else{
                if(this.arrcontent[i].name == "装量"){
                  this.arrcontent[i].details = "每袋装" + this.ruleForm.pelletWeight + 'g'
                }
                if(this.arrcontent[i].type == "规格" && this.type1 != "c50tj"){
                  this.arrcontent[i].details = this.arrcontent[i].detailone + this.ruleForm.loadingQuantity + "g"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"g"
                }
              }
            }
          },
			getfenlei(e){
				this.fenlei = e
				this.type1 = e.type
				this.arrcontent = e.content
				this.printname = e.templateName
				this.arrcontent = JSON.parse(this.arrcontent)
				for (var i = 0; i < this.arrcontent.length; i++) {
					if(this.mubans == '打印模板（国标）-上海'){
						console.log(this.arrcontent[i].type)
						if(this.arrcontent[i].name == "销售备案号"){
						let arrlist = JSON.parse(this.ruleForm.sellRecord)
						for (let j = 0; j < arrlist.length; j++) {
							if(arrlist[j].address == '上海'){
							this.arrcontent[i].details = arrlist[j].recordCode
							}
						}
						// this.arrcontent[i].details = this.ruleForm.batch
						}
					}
					if(this.arrcontent[i].type == "批号"){
						this.arrcontent[i].details = this.ruleForm.batch
					}
					if(this.arrcontent[i].type == "生产日期"){
						this.arrcontent[i].details = this.ruleForm.scTime
					}
					if(this.arrcontent[i].type == "有效期至"){
						this.arrcontent[i].details = this.ruleForm.deadLine + "个月"
					}
					// console.log(this.arrcontent[i])
					if(this.arrcontent[i].type == "规格" && this.type1 == "c50tj"){
						this.arrcontent[i].details =  this.ruleForm.loadingQuantity + "克"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"克"
					}

					if(this.arrcontent[i].name == "贮藏"){
						this.arrcontent[i].details = this.ruleForm.storage
					}
					if(this.arrcontent[i].name == "中药饮片执行标准"){
						this.arrcontent[i].details = this.ruleForm.zyyp
					}
					if(this.arrcontent[i].name == "中药配方颗粒执行标准"){
						this.arrcontent[i].details = this.ruleForm.zypf
					}
					if(this.arrcontent[i].name == "生产备案号"){
						this.arrcontent[i].details = this.ruleForm.prodRecordCode
					}
					if(this.arrcontent[i].name == "产地"){
						this.arrcontent[i].details = this.ruleForm.address
					}
					if(this.type1 == 'c60pt'|| this.type1 == 'c70pt'){
						if(this.arrcontent[i].name == "装量"){
							this.arrcontent[i].details = "每袋装" + this.ruleForm.pelletWeight + 'g'
						}
						if(this.arrcontent[i].type == "规格" && this.type != "c50tj"){
							this.arrcontent[i].details = this.arrcontent[i].detailone + this.ruleForm.loadingQuantity + "g"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"g"
						}
					}else{
						if(this.arrcontent[i].name == "装量"){
							this.arrcontent[i].details = "每袋装" + this.ruleForm.pelletWeight + '克'
						}
						if(this.arrcontent[i].type == "规格" && this.type1 != "c50tj"){
							this.arrcontent[i].details = this.arrcontent[i].detailone + this.ruleForm.loadingQuantity + "克"+ this.arrcontent[i].details + this.ruleForm.ypQuantity+"克"
						}
					}
				}
			},
            backPage () {
                this.$router.go(-1);
            },
            init(){
                print_findMsg(this.id).then((res) =>{

                    this.ruleForm = res.data
                    this.ruleForm.scTime = res.data.scTime.replace(/-/g,".")
                    this.ruleForm.deadLine = res.data.deadLine.replace(/-/g,".")
                    var code = (this.ruleForm.inventoryCode).toLowerCase()
                    code = code.substring(0,3)
                    var c50tj = (this.ruleForm.inventoryCode).toLowerCase()
                    c50tj = c50tj.substring(c50tj.length-2)
					// console.log(code)
					this.type = this.ruleForm.inventoryType
					this.code1 = this.type.substring(0,3).toLowerCase()
					// console.log(code1)
       //              if (code == 'c50') {
       //                  this.show = true
                        this.barCode = this.ruleForm.dispenserCode + ' ' + 0 + ' ' + this.ruleForm.batch
       //                  if (c50tj == 'tg') {
       //                      this.C50tj = true
				// 			if(this.muban == "打印模板（省标）"){
				// 				this.getoldprint()
				// 			}else{
				// 				this.getnewprint()
				// 			}
                  if(this.ruleForm.inventoryType == 'C60中药配方颗粒' || this.ruleForm.inventoryType == 'C70中药配方颗粒'){
                    this.mubans = '打印模板（国标）'
                    this.getmuban('打印模板（国标）')
                  }
                  if(this.ruleForm.inventoryType == 'C80中药配方颗粒'){
                    this.mubans = '打印模板（省标）'
                    this.getmuban('打印模板（省标）')
                  }
              if(this.ruleForm.inventoryType == 'C90中药配方颗粒'){
                this.mubans = '打印模板（省标）-执行标准-详见二维码'
                this.getmuban('打印模板（省标）-执行标准-详见二维码')
              }

              // this.getmuban('打印模板（省标）-执行标准-详见二维码')



       //                  } else{
       //                      this.c50tj = false
       //                  }
       //              } else {
       //                  this.show = false
       //              }
                })
            },
            changeNum(val){
                var num = Math.floor(val)

                if (num <= 0) {
                    this.$notify.error({
                        title: '提示',
                        message: '数量不能为零或负数！',
                        showClose: false,
                        duration:2000
                    });
                    this.ruleForm.printNum = ''
                }
                if (num > this.most) {
                    this.$notify.error({
                        title: '提示',
                        message: '数量不能大于未打印数量！',
                        showClose: false,
                        duration:2000
                    });
                    this.ruleForm.printNum = ''
                }
            },
            submitRules(formName){

                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$confirm('提交打印数据, 是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
							this.disabled = true
                            var code = (this.ruleForm.inventoryCode).toLowerCase()
                            code = code.substring(0,3)
                            var content = "{";
                            // C20开头
                            var c50tj = (this.ruleForm.inventoryCode).toLowerCase()
                            c50tj = c50tj.substring(c50tj.length-2)

							if(this.mubans == "打印模板（省标）"){
								if (this.type == "C20中药配方颗粒") {
								let param = {
									type:'c20',
									modal:'C20中药配方颗粒',
									breedName:this.ruleForm.breedName,
									// barCode:''
									// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}

								for(var i=0;i<this.content.length;i++){
									param[this.content[i].name] = this.content[i].details
								}
								for(var key in param){
									content+="\""+key+"\":"+"\""+param[key]+"\",";
								}

                                content = content.substring(0,content.length-1)+"}";
                            }
                            if (this.type == "C20连袋中药配方颗粒") {
                            	let param = {
                            		type:'c20',
                            		breedName:this.ruleForm.breedName,
									modal:'C20连袋中药配方颗粒',
                            		// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
                            	}

                            	for(var i=0;i<this.content3.length;i++){
                            		param[this.content3[i].name] = this.content3[i].details
                            	}
                            	for(var key in param){
                            		content+="\""+key+"\":"+"\""+param[key]+"\",";
                            	}

                                content = content.substring(0,content.length-1)+"}";
                            }



                            if (this.type == "C50中药配方颗粒") {
                               let param = {
                               	type:'c50',
								barCode:this.barCode,
								modal:'C50中药配方颗粒',
                               	breedName:this.ruleForm.breedName,
                               	// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
								url:'http://sy.xinlvyao.com:10109/n/index.html?code='
                               }

                               for(var i=0;i<this.content1.length;i++){
                               	param[this.content1[i].name] = this.content1[i].details
                               }
                               for(var key in param){
                               	content+="\""+key+"\":"+"\""+param[key]+"\",";
                               }

                               content = content.substring(0,content.length-1)+"}";
                            }

							if (this.type == "C51中药配方颗粒") {
							   let param = {
							   	type:'c51',
								barCode:this.barCode,
								modal:'C51中药配方颗粒',
							   	breedName:this.ruleForm.breedName,
							   	// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
								url:'http://sy.xinlvyao.com:10109/n/index.html?code='
							   }

							   for(var i=0;i<this.content4.length;i++){
							   	param[this.content4[i].name] = this.content4[i].details
							   }
							   for(var key in param){
							   	content+="\""+key+"\":"+"\""+param[key]+"\",";
							   }

							   content = content.substring(0,content.length-1)+"}";
							}

                            // 判断是C50开头 天津
                            if (this.type == "C50天津中药配方颗粒") {
                               let param = {
									type:'c50',
									barCode:this.barCode,
									modal:'C50天津中药配方颗粒',
									breedName:this.ruleForm.breedName,
									// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}

								for(var i=0;i<this.content2.length;i++){
									param[this.content2[i].name] = this.content2[i].details
								}
								for(var key in param){
									content +="\""+key+"\":"+"\""+param[key]+"\",";
								}

								   content = content.substring(0,content.length-1)+"}";
                            }

                            if (this.type == "C60中药配方颗粒") {
                               let param = {
									type:'c60',
									barCode:this.barCode,
									modal:'C60中药配方颗粒',
									breedName:this.ruleForm.breedName,
									// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}

								for(var i=0;i<this.content6.length;i++){
									param[this.content6[i].name] = this.content6[i].details
								}
								for(var key in param){
									content +="\""+key+"\":"+"\""+param[key]+"\",";
								}

								   content = content.substring(0,content.length-1)+"}";
                            }

                            if (this.type == "C70中药配方颗粒") {
                               let param = {
									type:'c70',
									barCode:this.barCode,
									modal:'C70中药配方颗粒',
									breedName:this.ruleForm.breedName,
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}

								for(var i=0;i<this.content7.length;i++){
									param[this.content7[i].name] = this.content7[i].details

								}
								for(var key in param){
									content +="\""+key+"\":"+"\""+param[key]+"\",";
								}


								   content = content.substring(0,content.length-1)+"}";
                            }
							if (this.type == "C80中药配方颗粒") {
							   let param = {
									type:'c80',
									barCode:this.barCode,
									modal:'C80中药配方颗粒',
									breedName:this.ruleForm.breedName,
									// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}

								for(var i=0;i<this.content8.length;i++){
									param[this.content8[i].name] = this.content8[i].details

								}
								for(var key in param){
									content +="\""+key+"\":"+"\""+param[key]+"\",";
								}


								   content = content.substring(0,content.length-1)+"}";
								}
								if (this.type == "C90中药配方颗粒") {
								   let param = {
										type:'c90',
										barCode:this.barCode,
										modal:'C90中药配方颗粒',
										breedName:this.ruleForm.breedName,
										// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
										url:'http://sy.xinlvyao.com:10109/n/index.html?code='
									}

									for(var i=0;i<this.content9.length;i++){
										param[this.content9[i].name] = this.content9[i].details

									}
									for(var key in param){
										content +="\""+key+"\":"+"\""+param[key]+"\",";
									}


									   content = content.substring(0,content.length-1)+"}";
								}


								if(this.fenlei.type == "c80pt" || this.fenlei.type == "c90pt"){
									if(!this.ruleForm.zyyp){
									   this.$notify.error({
											title: '提示',
											message: "中药饮片执行标准不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}
									if(!this.ruleForm.zypf){
									   this.$notify.error({
											title: '提示',
											message: "中药配方颗粒执行标准不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}

									if(!this.ruleForm.prodRecordCode){

									   this.$notify.error({
											title: '提示',
											message: "上市备案号不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}
								}
							}else{
								// console.log(this.fenlei)
								if(this.fenlei.type == "c70pt" || this.fenlei.type == "c60pt"){
									if(!this.ruleForm.zyyp){
									   this.$notify.error({
											title: '提示',
											message: "中药饮片执行标准不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}
									if(!this.ruleForm.zypf){
									   this.$notify.error({
											title: '提示',
											message: "中药配方颗粒执行标准不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}
									if(!this.ruleForm.prodRecordCode){

									   this.$notify.error({
											title: '提示',
											message: "上市备案号不能为空",
											showClose: false,
											duration:2000
										});
									   return false
									}
								}
								var s = this.fenlei.type.substring(0,3)
								 let param = {
									type:s,
									barCode:this.barCode,
									modal: this.fenlei.templateName,
									breedName:this.ruleForm.breedName,
									// url:window.location.protocol+"//"+window.location.host+"/n/index.html?code="
									url:'http://sy.xinlvyao.com:10109/n/index.html?code='
								}
								for(var i=0;i<this.arrcontent.length;i++){
									param[this.arrcontent[i].name] = this.arrcontent[i].details
								}
								for(var key in param){
									content +="\""+key+"\":"+"\""+param[key]+"\",";
								}


								   content = content.substring(0,content.length-1)+"}";
								// console.log(s)
							}

                          if(!this.ruleForm.address){
                            this.$notify.error({
                              title: '提示',
                              message: "产地不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.batch){
                            this.$notify.error({
                              title: '提示',
                              message: "批次不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.breedName){
                            this.$notify.error({
                              title: '提示',
                              message: "品名不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.deadLine){
                            this.$notify.error({
                              title: '提示',
                              message: "保质期不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.loadingQuantity){
                            this.$notify.error({
                              title: '提示',
                              message: "规格不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.pelletWeight){
                            this.$notify.error({
                              title: '提示',
                              message: "装量不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }
                          if(!this.ruleForm.storage){
                            this.$notify.error({
                              title: '提示',
                              message: "贮藏不能为空",
                              showClose: false,
                              duration:2000
                            });
                            return false
                          }

                            print_send({
                                "printId":this.id,
                                "printNum":this.ruleForm.printNum,
                                "content":content
                            }).then((res) =>{
                                if (res.mongoStatus == '1'||res.sendStatus == "1") {
                                    this.$notify.error({
                                        title: '提示',
                                        message: res.msg,
                                        showClose: false,
                                        duration:2000
                                    });
                                } else{
                                    this.$notify({
                                        title: '提示',
                                        message: '提交成功',
                                        type: 'success',
                                        duration:1000
                                    });
                                    this.backPage()
                                }
                            })
                        });
                    } else {
                        return false;
                    }
                })
            },
        }
    }
</script>

<style lang="less" scoped>
.el-pagination{
    text-align: center;
}
.el-radio__input.is-checked+.el-radio__label{
    display: none;
}
.codeView{
    position: relative;
    padding-left: 30px;
    .el-radio{
        position: absolute;
        left: 0;
        top: 30%;
        .el-radio__label{
            display: none;
        }
    }
    h5{ font-size: 18px; color: #303133; margin-bottom: 10px;}
    .el-form-item{ margin-bottom: 0;}
	.img{
		width: 15%;
		position: absolute;
		right: 10px;
		top: 5px;
		img{
			width: 100%;
			display: block;
		}
	}
    // .img{ position: absolute; right: -35px; top: 50px;}
}
.codeViewC50{
    padding: 10px 20px;
    .el-radio{
        position: absolute;
        left: -22px;
        top: 50%;
        .el-radio__label{
            display: none;
        }
    }
    p{
        // width: 218px;
        text-align: center;
        display: inline-block;
    }
    h5{
        display: block;
        width: 245px;
        text-align: center;
    }
}
</style>
